package enumdemo;

import util.Print;

/**
 * 枚举的基本方法
|values|返回枚举的值的数组|
|ordinal|返回枚举值在数组中位置|
|equals|判断两个枚举是否相等|
|hasCode|枚举值的hash|
|compareTo|枚举值可以比较|
|Serializable|序列化|
|name|枚举值的名称|
|Enum.valueOf|获取某个枚举的指定枚举值|
 * @author huchao
 */
public class EnumABC {

	public static void main(String[] args) {
		Shrubbery[] shrubberys = Shrubbery.values();
		for(Shrubbery s: shrubberys) {
			Print.print(s + " ordinal " + s.ordinal());//返回枚举值在数组中位置
			Print.print("is " + s + " equals Shrubbery.CRAWLING:" + s.equals(Shrubbery.CRAWLING));//判断两个枚举是否相等
			Print.print("compareTo Shrubbery.CRAWLING"
						+ String.format("(%s)", Shrubbery.CRAWLING.ordinal()) 
						+ s.compareTo(Shrubbery.CRAWLING));//下标的比较
			Print.print("s == Shrubbery.CRAWLING:" + (s == Shrubbery.CRAWLING));//可以使用==判断
			Print.print("DeclaringClass:" + s.getDeclaringClass() + " ");
			Print.print("name:" + s.name());
			Print.print("------------------------");
		}

		for(String s:"GROUND,CRAWLING,HANGING".split(",")) {
			Shrubbery sh = Enum.valueOf(Shrubbery.class,s);//获取某个枚举的指定枚举值
			Print.print(sh+" ");
		}
	}
}

enum Shrubbery {
	GROUND,CRAWLING,HANGING;
}
